package sanrenxing.dayEnd.backRepertoryTotal.dao;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import sanrenxing.dayEnd.backRepertoryTotal.domain.CashStock;
import sanrenxing.dayEnd.backRepertoryTotal.domain.CashStockTwo;

import java.util.List;
import java.util.Map;

/**
 * 功能：现金库存的数据层接口
 * 作者：赵思睿
 * 日期：2021/3/16 0016-10:21
 * 版本：1.0
 */
@Repository
public interface CashStockDao {
    /**
     * 将现金库存信息添加到数据库表中
     * @param cashStock 现金库存对象
     * @return 1：添加成功；0：添加失败
     */
    @Insert("insert into cashStock values(#{cashId},#{fundId},#{caId},#{caMoney},#{time})")
    public int add(CashStock cashStock);

    /**
     * 根据现金库存编号删除现金库存对象
     * @param cashId 现金库存编号
     * @return 1：删除成功；0：删除失败
     */
    @Delete("delete from cashStock where cashId=#{cashId}")
    public int delete(@Param("cashId") String cashId);

    /**
     * 查询所有现金库存信息
     * @param map 映射集合对象
     * @return 现金库存对象集合
     */
    @Select("<script>" +
            "select c.cashId,f.fundName,ca.accName,c.caMoney,c.time from " +
            "((select rownum rn,cashStock.* from cashStock <where>#{end}>=rownum</where>) c) " +
            "join fundSetup f on c.fundId=f.fundId join cashAccount ca on c.caId=ca.caId" +
            "<where>" +
            /*"<if test='cashStock.cashId!=null'>" +
            " and cashId like '%${cashStock.cashId}%'" +
            "</if>" +*/
            "<if test='cashStock.time!=null'>" +
            " and to_char(time,'yyyy-MM-dd')=#{cashStock.time}" +
            "</if>" +
            " and rn>=#{start}" +
            "</where>" +
            "</script>")
    public List<CashStockTwo> selectAll(Map<String, Object> map);

    /**
     * 统计记录数
     * @return 记录数
     */
    @Select("select count(*) as counts from cashStock")
    public int count();
}
